package com.handu.luna.core.domain.goods;


import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.handu.luna.core.domain.BaseRepository;

public interface AlbumRepository extends JpaRepository<Album,Long>, BaseRepository<Album>,JpaSpecificationExecutor<Album>{

	
	/**
	 * 查询对应的商品相册
	 **/
	 
	@Query("select b from Album b where b.goodId =:goodId")
	List<Album> findByGoodsId(@Param("goodId") long goodId);
	
	/**
	 * 删除对应的商品图片
	 **/
	@Query("delete from Album c   where c.id =  :id and c.goodId = :goodId  ")
	void deletePic(@Param("id") long id,@Param("goodId") long goodId);
	
	@Query("select picAddress from Album c where c.goodId = :goodsId order by c.picSort")
	Page<String> findAddressByGoodsId(@Param("goodsId") long goodsId ,Pageable pagealbe);


    @Query("select a from Album a where a.goodId = ?1 order by a.picSort")
    Page<Album> findByGoodsId(long goodsId,Pageable pageable);
}
